package com.dyh.quickdemo.Spy;

import org.junit.jupiter.api.Test;

/*
@Author=Joey Wheeler
@Date=2021/4/13 18:04
*/

public class SpyThreadDemo {

    {
        System.err.println();
    }

    /*不用cucMap 会出现spy不一致的情况 后面的认为没有spy 就替换了
    *
    * cucMap始终会保证先来的不会被剥夺
    * */
    @Test
    public void test() throws InterruptedException {

//        Spy spy = new BaseSpy(System.out::println);
//        Runnable r = ()->{
//            SpyHeadquarters.watch("a",spy);
//        };
        new Thread(()->{
            SpyHeadquarters.watch("a",new BaseSpy(System.out::println));
            SpyHeadquarters.get("a").addRecord("11");
        }).start();

        new Thread(()->{
            SpyHeadquarters.watch("a",new BaseSpy(System.err::println));
            SpyHeadquarters.get("a").addRecord("22");

        }).start();








        Thread.sleep(1000L*2);
        SpyHeadquarters.get("a").doReport();
        System.out.println();
    }


}
